home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UTEDocument.cp < prev    next >
Encoding:
Text File  |  1991-05-01  |  22.2 KB  |  865 lines  |  [TEXT/MPS ]

  1. // UTEDocument.cp 
  2. // Copyright © 1990-1991 by Apple Computer, Inc.    All rights reserved.
  3.  
  4. #ifndef __GEOMETRY__
  5. #include <Geometry.h>
  6. #endif
  7.  
  8. #ifndef __ULIST__
  9. #include <UList.h>
  10. #endif
  11.  
  12. #ifndef __ALIASES__
  13. #include <Aliases.h>
  14. #endif
  15.  
  16. #ifndef __UFILE__
  17. #include <UFile.h>
  18. #endif
  19.  
  20. #ifndef __EDITIONS__
  21. #include <Editions.h>
  22. #endif
  23.  
  24. #ifndef __DIALOGS__
  25. #include <Dialogs.h>
  26. #endif
  27.  
  28. #ifndef __UAPPLICATION__
  29. #include <UApplication.h>
  30. #endif
  31.  
  32. #ifndef __UPRINTHANDLER__
  33. #include <UPrintHandler.h>
  34. #endif
  35.  
  36. #ifndef __BALLOONS__
  37. #include <Balloons.h>
  38. #endif
  39.  
  40. #ifndef __UVIEW__
  41. #include <UView.h>
  42. #endif
  43.  
  44. #ifndef __UWINDOW__
  45. #include <UWindow.h>
  46. #endif
  47.  
  48. #ifndef __UTEVIEW__
  49. #include <UTEView.h>
  50. #endif
  51.  
  52. #ifndef __PRINTING__
  53. #include <Printing.h>
  54. #endif
  55.  
  56. #ifndef __UPRINTING__
  57. #include <UPrinting.h>
  58. #endif
  59.  
  60. #ifndef __UFAILURE__
  61. #include <UFailure.h>
  62. #endif
  63.  
  64. #ifndef __UMACAPPUTILITIES__
  65. #include <UMacAppUtilities.h>
  66. #endif
  67.  
  68. #ifndef __MENUS__
  69. #include <Menus.h>
  70. #endif
  71.  
  72. #ifndef __UMENUMGR__
  73. #include <UMenuMgr.h>
  74. #endif
  75.  
  76. #ifndef __UPATCH__
  77. #include <UPatch.h>
  78. #endif
  79.  
  80. #ifndef __UMACAPPGLOBALS__
  81. #include <UMacAppGlobals.h>
  82. #endif
  83.  
  84. #ifndef __UMEMORY__
  85. #include <UMemory.h>
  86. #endif
  87.  
  88. #ifndef __UERRORMGR__
  89. #include <UErrorMgr.h>
  90. #endif
  91.  
  92. #ifndef __FONTS__
  93. #include <Fonts.h>
  94. #endif
  95.  
  96. #ifndef __RESOURCES__
  97. #include <Resources.h>
  98. #endif
  99.  
  100. #ifndef __TOOLUTILS__
  101. #include <ToolUtils.h>
  102. #endif
  103.  
  104. #ifndef __PACKAGES__
  105. #include <Packages.h>
  106. #endif
  107.  
  108. #ifndef __PICKER__
  109. #include <Picker.h>
  110. #endif
  111.  
  112. #ifndef __ERRORS__
  113. #include <Errors.h>
  114. #endif
  115.  
  116. #ifndef __UTEDOCUMENT__
  117. #include <UTEDocument.h>
  118. #endif
  119.  
  120. #ifndef __UTECOMMANDS__
  121. #include <UTECommands.h>
  122. #endif
  123.  
  124. #ifndef __UVIEWSERVER__
  125. #include <UViewServer.h>
  126. #endif
  127.  
  128. //--------------------------------------------------------------------------------------------------
  129. TextSpecs gDefaultSpecs;                        // ??? used but never initialized below !!!
  130.  
  131. //--------------------------------------------------------------------------------------------------
  132. #pragma segment TEDocOpen
  133. pascal void TTEDocument::Initialize(void)        // override 
  134. {
  135.     inherited::Initialize();
  136.     fDocText = NULL;
  137.     fElements = NULL;
  138.     fStyles = NULL;
  139.     fTEView = NULL;
  140.     fTextSpecs = gDefaultSpecs;
  141. }
  142.  
  143. //--------------------------------------------------------------------------------------------------
  144. #pragma segment TEDocOpen
  145.  
  146. pascal void TTEDocument::ITEDocument(TFile* itsFile,
  147.                                      const OSType itsFileType,
  148.                                      const OSType itsCreator,
  149.                                      const OSType itsScrapType,
  150.                                      Boolean usesDataFork,
  151.                                      Boolean usesRsrcFork,
  152.                                      Boolean keepsDataOpen,
  153.                                      Boolean keepsRsrcOpen)
  154. {
  155.     this->IFileBasedDocument(itsFile, itsFileType, itsCreator, itsScrapType, usesDataFork, usesRsrcFork, keepsDataOpen, keepsRsrcOpen);
  156.  
  157.     fDocText = NewPermHandle(0);
  158. }
  159.  
  160. //--------------------------------------------------------------------------------------------------
  161. #pragma segment TEDocClose
  162.  
  163. pascal void TTEDocument::Free(void)                // override 
  164. {
  165.     fDocText = DisposeIfHandle(fDocText);
  166.  
  167.     inherited::Free();
  168. }
  169.  
  170. //--------------------------------------------------------------------------------------------------
  171. #pragma segment TEDocNonRes
  172.  
  173. pascal void TTEDocument::ChangeBackColor(const RGBColor& newColor)
  174. {
  175.     GrafPtr oldPort;
  176.     TView * itsRootView;
  177.  
  178.     //??? Is this right?  Should we set the background color even if
  179.     // the view isn't in a window yet?
  180.     GetPort(oldPort);
  181.     SetPort((*fTEView->fHTE)->inPort);
  182.     RGBBackColor(newColor);
  183.     itsRootView = fTEView->GetRootView();
  184.     if (itsRootView)
  185.         itsRootView->ForceRedraw();
  186.     SetPort(oldPort);
  187. }
  188.  
  189. //--------------------------------------------------------------------------------------------------
  190. #pragma segment TEDocOpen
  191.  
  192. pascal void TTEDocument::DoInitialState(void)    // override 
  193. {
  194.     fTextSpecs = gDefaultSpecs;
  195. }
  196.  
  197. //--------------------------------------------------------------------------------------------------
  198. #pragma segment TEDocOpen
  199.  
  200. pascal void TTEDocument::DoMakeViews(Boolean forPrinting)// override 
  201.  
  202. {
  203.     TView * aView;
  204.     TStdPrintHandler * aHandler;
  205.  
  206.     if (forPrinting)
  207.     // We're only finder printing--don't need a window, just the view being printed 
  208.         aView = gViewServer->DoCreateViews(this, NULL, kViewRsrcID, gZeroVPt);
  209.     else
  210.         aView = gViewServer->NewTemplateWindow(kWindowRsrcID, this);
  211.  
  212.     aView = aView->FindSubView('TEVW');
  213.     fTEView = (TTEView *)aView;                    // Must cast because FindSubView returns TView
  214.     aHandler = new TStdPrintHandler;
  215.     aHandler->IStdPrintHandler(this,            // its document 
  216.                                fTEView,            // its view 
  217.                                !kSquareDots,    // does not have square dots 
  218.                                kFixedSize,        // horzontal page size is fixed 
  219.                                !kFixedSize);    // vertical page size is variable (could be
  220.     // set to true on non-style TE systems)
  221.  
  222.     this->ShowReverted();
  223. }
  224.  
  225. //--------------------------------------------------------------------------------------------------
  226. #pragma segment TEDocSelCommand
  227.  
  228. void TTEDocument::DoJustChange(CmdNumber aCmdNumber)
  229. {
  230.     short newJust;
  231.     TJustCommand * aJustChange;
  232.  
  233.     switch (aCmdNumber)
  234.     {
  235.         case cJustSystem:
  236.             newJust = teFlushDefault;
  237.             break;
  238.             
  239.         case cJustForceLeft:
  240.             newJust = teFlushLeft;
  241.             break;
  242.             
  243.         case cJustCenter:
  244.             newJust = teCenter;
  245.             break;
  246.             
  247.         case cJustRight:
  248.             newJust = teFlushRight;
  249.             break;
  250.     };
  251.     aJustChange = new TJustCommand;
  252.     aJustChange->IJustCommand(fTEView, newJust);
  253.     fTextSpecs.theJustification = newJust;
  254.     this->PostCommand(aJustChange);
  255. }
  256.  
  257. //--------------------------------------------------------------------------------------------------
  258. #pragma segment TEDocSelCommand
  259.  
  260. void TTEDocument::DoStyleChange(CmdNumber aCmdNumber)
  261. {
  262.     TextStyle newStyle;
  263.  
  264.     switch (aCmdNumber)
  265.     {
  266.         case cBold:
  267.             newStyle.tsFace = bold;
  268.             break;
  269.             
  270.         case cItalic:
  271.             newStyle.tsFace = italic;
  272.             break;
  273.             
  274.         case cUnderline:
  275.             newStyle.tsFace = underline;
  276.             break;
  277.             
  278.         case cOutline:
  279.             newStyle.tsFace = outline;
  280.             break;
  281.             
  282.         case cShadow:
  283.             newStyle.tsFace = shadow;
  284.             break;
  285.             
  286.         case cCondense:
  287.             newStyle.tsFace = condense;
  288.             break;
  289.             
  290.         case cExtend:
  291.             newStyle.tsFace = extend;
  292.             break;
  293.     }
  294.     if ((newStyle.tsFace * fTextSpecs.theTextFace) == newStyle.tsFace)
  295.         fTextSpecs.theTextFace -= newStyle.tsFace;
  296.     else
  297.         fTextSpecs.theTextFace += newStyle.tsFace;
  298.     this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cStyleChange, doFace + doToggle));
  299. }
  300.  
  301. //--------------------------------------------------------------------------------------------------
  302. #pragma segment TEDocSelCommand
  303.  
  304. void TTEDocument::DoColTextChange()
  305. {
  306.     TextStyle newStyle;
  307.     RGBColor aColor;
  308.     Str255 promptString;
  309.  
  310.     aColor = fTextSpecs.theTextColor;
  311.     GetIndString(promptString, kPromptsRsrcID, kColTextPrompt);
  312.     if (GetColor(Point(64, 64), promptString, aColor, newStyle.tsColor))
  313.     {
  314.         fTextSpecs.theTextColor = newStyle.tsColor;
  315.         this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cColorChange, doColor + doToggle));
  316.     }
  317. }
  318.  
  319. //--------------------------------------------------------------------------------------------------
  320. #pragma segment TEDocSelCommand
  321.  
  322. void TTEDocument::DoColBackChange()
  323. {
  324.     TextStyle newStyle;
  325.     RGBColor aColor;
  326.     Str255 promptString;
  327.  
  328.     aColor = fTextSpecs.theBackColor;
  329.     GetIndString(promptString, kPromptsRsrcID, kColBackPrompt);
  330.     if (GetColor(Point(64, 64), promptString, aColor, newStyle.tsColor))
  331.     {
  332.         fTextSpecs.theBackColor = newStyle.tsColor;
  333.         this->ChangeBackColor(newStyle.tsColor);
  334.     }
  335. }
  336.  
  337. //--------------------------------------------------------------------------------------------------
  338. #pragma segment TEDocSelCommand
  339.  
  340. void TTEDocument::InstallChangedDeterminer(VHSelect vhs,
  341.                                            SizeDeterminer sd)
  342. {
  343.     if (sd != fTEView->fSizeDeterminer[vhs])
  344.     {
  345.         fTEView->fSizeDeterminer[vhs] = sd;
  346.  
  347.         // If we changed the horizontal size determiner,
  348.         //  we must ask the TTEView to recompute the TE rectangles.
  349.         if (vhs == hSel)
  350.         {
  351.             if (sd == sizeSuperView)
  352.                 fTEView->SuperViewChangedSize(gZeroVPt, TRUE);// Don't care about deltas
  353.             else if (sd == sizePage)
  354.                 fTEView->DoPagination();
  355.         }
  356.  
  357.         fTEView->AdjustSize();
  358.         fTEView->ForceRedraw();
  359.     }
  360. }
  361.  
  362. //--------------------------------------------------------------------------------------------------
  363. #pragma segment TEDocSelCommand
  364.  
  365. void TTEDocument::DoWidthChange(CmdNumber aCmdNumber)
  366. {
  367.     SizeDeterminer sd;
  368.  
  369.     if (aCmdNumber == cWidthSuperView)
  370.         sd = sizeSuperView;
  371.     else if (aCmdNumber == cWidthOnePage)
  372.         sd = sizePage;
  373.     else
  374.         sd = sizeFixed;
  375.  
  376.     // NB: The following is not undoable in the
  377.     // current version
  378.     this->InstallChangedDeterminer(hSel, sd);
  379. }
  380.  
  381. //--------------------------------------------------------------------------------------------------
  382. #pragma segment TEDocSelCommand
  383.  
  384. void TTEDocument::DoHeightChange(CmdNumber aCmdNumber)
  385. {
  386.     SizeDeterminer sd;
  387.  
  388.     switch (aCmdNumber)
  389.     {
  390.         case cHeightSuperView:
  391.             sd = sizeSuperView;
  392.             break;
  393.             
  394.         case cHeightPages:
  395.             sd = sizeFillPages;
  396.             break;
  397.             
  398.         case cHeightText:
  399.             sd = sizeVariable;
  400.             break;
  401.             
  402.         case cHeightConst:
  403.             sd = sizeFixed;
  404.             break;
  405.     }
  406.  
  407.     // NB: The following is not undoable in the
  408.     // current version
  409.     this->InstallChangedDeterminer(vSel, sd);
  410. }
  411.  
  412. //--------------------------------------------------------------------------------------------------
  413. #pragma segment TEDocSelCommand
  414.  
  415. pascal void TTEDocument::DoMenuCommand(CmdNumber aCmdNumber)// override 
  416. {
  417.     Str255 aName;
  418.     short menu;
  419.     short item;
  420.     TextStyle newStyle;
  421.  
  422.     CmdToMenuItem(aCmdNumber, menu, item);
  423.  
  424.     if (menu == mFont)
  425.     {
  426.         GetItem(GetMHandle(menu), item, aName);
  427.         GetFNum(aName, newStyle.tsFont);
  428.         fTextSpecs.theTextFont = aName;
  429.         this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cFontChange, doFont + doToggle));
  430.     }
  431.     else if ((aCmdNumber > cSizeBase) && (aCmdNumber <= cSizeMax))
  432.     {
  433.         newStyle.tsSize = (short)(aCmdNumber - cSizeBase);
  434.         fTextSpecs.theTextSize = newStyle.tsSize;
  435.         this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cSizeChange, doSize + doToggle));
  436.     }
  437.     else
  438.         switch (aCmdNumber)
  439.         {
  440.             case cSizeOther:
  441.                 // as yet unsupported
  442.                 break;
  443.  
  444.             case cSizeGrow:
  445.             case cSizeShrink:
  446.                 if (aCmdNumber == cSizeGrow)
  447.                 {
  448.                     newStyle.tsSize = kRelSizeAmount;
  449.                     fTextSpecs.theTextSize += kRelSizeAmount;
  450.                 }
  451.                 else
  452.                 {
  453.                     newStyle.tsSize = -kRelSizeAmount;
  454.                     fTextSpecs.theTextSize -= kRelSizeAmount;
  455.                 }
  456.                 this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cSizeChange, doSize + addSize + doToggle));
  457.                 break;
  458.     
  459.             case cJustForceLeft:
  460.             case cJustCenter:
  461.             case cJustRight:
  462.             case cJustSystem:
  463.                 this->DoJustChange(aCmdNumber);
  464.                 break;
  465.     
  466.             case cPlainText:
  467.                 newStyle.tsFace = 0;
  468.                 fTextSpecs.theTextFace = 0;
  469.                 this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cStyleChange, doFace));
  470.                 break;
  471.     
  472.             case cBold:
  473.             case cItalic:
  474.             case cUnderline:
  475.             case cOutline:
  476.             case cShadow:
  477.             case cCondense:
  478.             case cExtend:
  479.                 this->DoStyleChange(aCmdNumber);
  480.                 break;
  481.     
  482.             case cColorText:
  483.                 this->DoColTextChange();
  484.                 break;
  485.     
  486.             case cColorBackground:
  487.                 this->DoColBackChange();
  488.                 break;
  489.     
  490.             case cWidthSuperView:
  491.             case cWidthView:
  492.             case cWidthOnePage:
  493.                 this->DoWidthChange(aCmdNumber);
  494.                 break;
  495.     
  496.             case cHeightSuperView:
  497.             case cHeightPages:
  498.             case cHeightText:
  499.             case cHeightConst:
  500.                 this->DoHeightChange(aCmdNumber);
  501.                 break;
  502.     
  503.             default:
  504.                 inherited::DoMenuCommand(aCmdNumber);
  505.                 break;
  506.         }
  507. }
  508.  
  509. //--------------------------------------------------------------------------------------------------
  510. #pragma segment TEDocWriteFile
  511.  
  512. pascal void TTEDocument::DoNeedDiskSpace(TFile* itsFile,
  513.                                          long& dataForkBytes,
  514.                                          long& rsrcForkBytes)// override 
  515. {
  516.     TEStyleHandle styles;
  517.     STHandle elements;
  518.  
  519.     dataForkBytes += GetHandleSize(fDocText);
  520.  
  521.     rsrcForkBytes += kPrintInfoSize + kRsrcTypeOverhead + kRsrcOverhead;
  522.  
  523.     if ((fTEView->fStyleType == kWithStyle) && (fTEView->fHTE))
  524.     {
  525.         fTEView->ExtractStyles(styles, elements);
  526.         rsrcForkBytes += GetHandleSize((Handle)styles) + kRsrcTypeOverhead + kRsrcOverhead + GetHandleSize((Handle)elements) + kRsrcTypeOverhead + kRsrcOverhead;
  527.     }
  528.  
  529.     rsrcForkBytes += sizeof(TextSpecs) + kRsrcTypeOverhead + kRsrcOverhead;
  530.  
  531.     // Get resource file overhead 
  532.     inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
  533. }
  534.  
  535. //--------------------------------------------------------------------------------------------------
  536. #pragma segment TEDocReadFile
  537.  
  538. pascal void TTEDocument::DoRead(TFile* aFile, Boolean forPrinting)        // override 
  539. {
  540.     long numChars;
  541.     TextSpecsHdl hTextSpecs;
  542.     Handle hPrintInfo;
  543.  
  544.     // Read in the print info
  545.     inherited::DoRead(aFile, forPrinting);
  546.  
  547.     FailOSErr(aFile->GetDataLength(numChars));    // Read in the text 
  548.  
  549.     if (numChars > kUnlimited)                    // The file may have been created by… 
  550.     {
  551.         // …someone else - limit it to 32K! 
  552.         gApplication->ShowError(0, msgAlert + kFileTooBig);
  553.         numChars = kUnlimited;
  554.     }
  555.  
  556.     SetHandleSize(fDocText, numChars);
  557.     FailMemError();
  558.     FailOSErr(aFile->ReadData(*fDocText, numChars));
  559.  
  560.     fStyles =                                    // Read in the TEStyleRec 
  561.              (TEStyleHandle)GetResource(kTextStyleRsrcType, kStylesRsrcID);
  562.     if (fStyles != NULL)
  563.         DetachResource((Handle)fStyles);
  564.  
  565.     fElements =                                    // Read in the STElement array 
  566.                (STHandle)(GetResource(kTextStyleRsrcType, kElementsRsrcID));
  567.     if (fElements != NULL)
  568.         DetachResource((Handle)fElements);
  569.  
  570.     hTextSpecs =                                // Read the text specs resource 
  571.                 (TextSpecsHdl)GetResource(kTextSpecsRsrcType, kTextSpecsRsrcID);
  572.     if (hTextSpecs != NULL)
  573.         fTextSpecs = **hTextSpecs;
  574.     else
  575.         this->DoInitialState();
  576. }
  577.  
  578. //--------------------------------------------------------------------------------------------------
  579. #pragma segment TEDocRes
  580.  
  581. pascal void TTEDocument::DoSetupMenus(void)        // override 
  582. {
  583.     Boolean checkPlain;
  584.     Boolean checkFont;
  585.     Boolean specChange;
  586.     short just;
  587.     short aMode;
  588.     Style aFace;
  589.     SizeDeterminer sd;
  590.     MenuHandle aMenuHandle;
  591.     Str255 aName;
  592.     TextStyle aStyle;
  593.     short theFont;
  594.     short startOfSelection,
  595.      endOfSelection;
  596.  
  597.     inherited::DoSetupMenus();
  598.  
  599.     startOfSelection = (*fTEView->fHTE)->selStart;
  600.     endOfSelection = (*fTEView->fHTE)->selEnd;
  601.  
  602.     aMode = doFace;
  603.     checkPlain = fTEView->ContinuousStyle(startOfSelection, endOfSelection, aMode, aStyle) && (aStyle.tsFace == 0);
  604.  
  605.     aMode = doAll;
  606.     aStyle.tsFace = bold | italic | underline | outline | shadow | extend | condense;
  607.  
  608.     specChange = fTEView->ContinuousStyle(startOfSelection, endOfSelection, aMode, aStyle);
  609.     checkFont = ((aMode & doFont) != 0);
  610.  
  611.     aMenuHandle = GetMHandle(mFont);
  612.     // If specs have changed && EITHER an old-style record || the font's continuous - Ed. 
  613.     specChange = (fTEView->fSpecsChanged && checkFont);
  614.  
  615.     GetFontName(aStyle.tsFont, aName);            // Get real font number in case tsFont is 
  616.     GetFNum(aName, theFont);                    // …the system or application font. 
  617.     for (short item = 1; item <= CountMItems(aMenuHandle); ++item)
  618.     {
  619.         // There can be more than 31 menu entries with scrolling menus, but trying to enable
  620.         // an item with number > 31 is bad news.  If the menu itself is enabled (which it
  621.         // will be in MacApp if any of the first 31 items is enabled), then the extras
  622.         // will always be enabled.
  623.         if (item <= 31)
  624.             EnableItem(aMenuHandle, item);
  625.         if (checkFont)
  626.         {
  627.             short fnt;
  628.  
  629.             GetItem(aMenuHandle, item, aName);
  630.             GetFNum(aName, fnt);
  631.             CheckItem(aMenuHandle, item, (fnt == theFont));
  632.         }
  633.     }
  634.  
  635.     sd = fTEView->fSizeDeterminer[hSel];        // Enable size determiner related menu items
  636.     EnableCheck(cWidthSuperView, TRUE, (sd == sizeSuperView));
  637.     EnableCheck(cWidthOnePage, TRUE, (sd == sizePage));
  638.     EnableCheck(cWidthView, TRUE, (sd == sizeFixed));
  639.  
  640.     sd = fTEView->fSizeDeterminer[vSel];
  641.     EnableCheck(cHeightSuperView, TRUE, (sd == sizeSuperView));
  642.     EnableCheck(cHeightPages, TRUE, (sd == sizeFillPages));
  643.     EnableCheck(cHeightText, TRUE, (sd == sizeVariable));
  644.     EnableCheck(cHeightConst, TRUE, (sd == sizeFixed));
  645.  
  646.     just = fTEView->fJustification;                // Enable justification related menu items 
  647.     EnableCheck(cJustSystem, TRUE, (just == teFlushDefault));
  648.     EnableCheck(cJustForceLeft, TRUE, (just == teFlushLeft));
  649.     EnableCheck(cJustCenter, TRUE, (just == teCenter));
  650.     EnableCheck(cJustRight, TRUE, (just == teFlushRight));
  651.  
  652.     Enable(cStyle, TRUE);                        // Enable sub-menus 
  653.     Enable(cSize, TRUE);
  654.     Enable(cFont, TRUE);
  655.     Enable(cColor, (qNeedsColorQD || gConfiguration.hasColorQD));
  656.  
  657.     aFace = aStyle.tsFace;
  658.     EnableCheck(cPlainText, TRUE, checkPlain);    // Enable normal Style menu items 
  659.     EnableCheck(cBold, TRUE, bold & aFace);
  660.     EnableCheck(cItalic, TRUE, italic & aFace);
  661.     EnableCheck(cUnderline, TRUE, underline & aFace);
  662.     EnableCheck(cOutline, TRUE, outline & aFace);
  663.     EnableCheck(cShadow, TRUE, shadow & aFace);
  664.     EnableCheck(cCondense, TRUE, condense & aFace);
  665.     EnableCheck(cExtend, TRUE, extend & aFace);
  666.  
  667.     for (short c = cSizeMin; c <= cSizeMax; ++c)
  668.     {
  669.         Boolean checkSize;
  670.  
  671.         if (!(aMode & doSize))
  672.             checkSize = FALSE;
  673.         else
  674.             checkSize = ((c - cSizeBase) == aStyle.tsSize);
  675.  
  676.         EnableCheck(c, TRUE, checkSize);
  677.         if (fTEView->fSpecsChanged)
  678.         {
  679.             // if it _is_ styled and font is continuous 
  680.             // …and the size is a real one
  681.             if ((aMode & doFont) && RealFont(aStyle.tsFont, c - cSizeBase))
  682.                 aFace = outline;                // …then we outline it 
  683.             else
  684.                 aFace = 0;
  685.             SetStyle(c, aFace);
  686.         }
  687.     }
  688.  
  689.     Enable(cSizeGrow, TRUE);
  690.     Enable(cSizeShrink, TRUE);
  691.  
  692.     Enable(cColorText, (qNeedsColorQD || gConfiguration.hasColorQD));
  693.     Enable(cColorBackground, (qNeedsColorQD || gConfiguration.hasColorQD));
  694.  
  695.     fTEView->fSpecsChanged = FALSE;
  696. }
  697.  
  698. //--------------------------------------------------------------------------------------------------
  699. #pragma segment TEDocWriteFile
  700.  
  701. pascal void TTEDocument::DoWrite(TFile* aFile, Boolean makingCopy)        // override 
  702. {
  703.     long numChars;
  704.     TextSpecsHdl hTextSpecs;
  705.     Handle tempHandle;
  706.     TEStyleHandle styles;
  707.     STHandle elements;
  708.  
  709.     // write out the print info
  710.     inherited::DoWrite(aFile, makingCopy);
  711.  
  712.     // Write out the text 
  713.     numChars = GetHandleSize(fDocText);
  714.     FailOSErr(aFile->WriteData(*fDocText, numChars));
  715.  
  716.     if (fTEView->fStyleType == kWithStyle)
  717.     {
  718.         fTEView->ExtractStyles(styles, elements);
  719.         FailOSErr(HandToHand((Handle&)styles));
  720.         AddResource((Handle)styles, kTextStyleRsrcType, kStylesRsrcID, "");
  721.         FailResError();
  722.         FailOSErr(HandToHand((Handle&)elements));
  723.         AddResource((Handle)elements, kTextStyleRsrcType, kElementsRsrcID, "");
  724.         FailResError();
  725.     }
  726.  
  727.     // Write the text specification resource, after converting it to a handle 
  728.     hTextSpecs = (TextSpecsHdl)NewPermHandle(sizeof(TextSpecs));
  729.     **hTextSpecs = fTextSpecs;
  730.     AddResource((Handle)hTextSpecs, kTextSpecsRsrcType, kTextSpecsRsrcID, "");
  731.     FailResError();
  732. }
  733.  
  734. //--------------------------------------------------------------------------------------------------
  735. #pragma segment TEDocClose
  736.  
  737. pascal void TTEDocument::FreeData(void)            // override 
  738. {
  739.     SetHandleSize(fDocText, 0);
  740. }
  741.  
  742. //--------------------------------------------------------------------------------------------------
  743. #pragma segment TEDocRes
  744.  
  745. pascal void TTEDocument::SetSpecStyle(void)
  746. {
  747.     short theFont;
  748.     TextStyle theTS;
  749.     Str255 aStr255;
  750.  
  751.     aStr255 = fTextSpecs.theTextFont;
  752.     GetFNum(aStr255, theFont);
  753.     SetTextStyle(theTS, theFont, fTextSpecs.theTextFace, fTextSpecs.theTextSize, fTextSpecs.theTextColor);
  754.     fTEView->SetOneStyle(0, 0, doAll, theTS, kDontRedraw);
  755. }
  756.  
  757. //--------------------------------------------------------------------------------------------------
  758. #pragma segment TEDocReadFile
  759.  
  760. pascal void TTEDocument::ShowReverted(void)        // override 
  761. {
  762.     RGBColor aColor;
  763.  
  764.     fTEView->StuffText(fDocText);                // put in the text 
  765.     TESetSelect(0, 0, fTEView->fHTE);
  766.     if (fStyles && fElements)                    // If we're able, stuff style info 
  767.         fTEView->StuffStyles(fStyles, fElements);
  768.     else
  769.         this->SetSpecStyle();
  770.  
  771.     if (qNeedsColorQD || gConfiguration.hasColorQD)
  772.     {
  773.         aColor = fTextSpecs.theBackColor;
  774.         this->ChangeBackColor(aColor);
  775.     }
  776.     fTEView->SetJustification(fTextSpecs.theJustification, kDontRedraw);
  777.     inherited::ShowReverted();
  778. }
  779.  
  780. //--------------------------------------------------------------------------------------------------
  781. #pragma segment TEDocFields
  782.  
  783. pascal void TTEDocument::Fields(TObject* obj)    // override 
  784.  
  785. {
  786.     obj->DoToField("TTEDocument", (Ptr)NULL, bClass);
  787.     obj->DoToField("fDocText", (Ptr) & fDocText, bHandle);
  788.     obj->DoToField("fTEView", (Ptr) & fTEView, bObject);
  789.     obj->DoToField("   fTextSpecs", (Ptr)NULL, bClass);
  790.     obj->DoToField(" theTextFont", (Ptr) & fTextSpecs.theTextFont, bString);
  791.     obj->DoToField(" theTextFace", (Ptr) & fTextSpecs.theTextFace, bStyle);
  792.     obj->DoToField(" theTextSize", (Ptr) & fTextSpecs.theTextSize, bInteger);
  793.     obj->DoToField(" theTextColor", (Ptr) & fTextSpecs.theTextColor, bRGBColor);
  794.     obj->DoToField(" theJustification", (Ptr) & fTextSpecs.theJustification, bInteger);
  795.     obj->DoToField(" theBackColor", (Ptr) & fTextSpecs.theBackColor, bRGBColor);
  796.  
  797.     inherited::Fields(obj);
  798. }
  799.  
  800. //******************************************************************************************
  801. //  T J u s t C o m m a n d 
  802. //******************************************************************************************
  803.  
  804. //--------------------------------------------------------------------------------------------------
  805. #pragma segment TEDocSelCommand
  806. pascal void TJustCommand::Initialize(void)        // override 
  807. {
  808.     inherited::Initialize();
  809.     fOldJust = teFlushDefault;
  810.     fNewJust = teFlushDefault;
  811.     fTEView = NULL;
  812. }
  813.  
  814. //--------------------------------------------------------------------------------------------------
  815. #pragma segment TEDocSelCommand
  816.  
  817. pascal void TJustCommand::IJustCommand(TTEView* itsTEView,
  818.                                        short itsNewJust)
  819. {
  820.     this->ICommand(cJustChange, itsTEView->fDocument, itsTEView);
  821.     fTEView = itsTEView;
  822.     fOldJust = itsTEView->fJustification;
  823.     fNewJust = itsNewJust;
  824. }
  825.  
  826. //--------------------------------------------------------------------------------------------------
  827. #pragma segment TEDocDoCommand
  828.  
  829. pascal void TJustCommand::DoIt(void)            // override 
  830. {
  831.     fTEView->SetJustification(fNewJust, kRedraw);
  832. }
  833.  
  834. //--------------------------------------------------------------------------------------------------
  835. #pragma segment TEDocDoCommand
  836.  
  837. pascal void TJustCommand::RedoIt(void)            // override 
  838. {
  839.     this->DoIt();
  840. }
  841.  
  842. //--------------------------------------------------------------------------------------------------
  843. #pragma segment TEDocDoCommand
  844.  
  845. pascal void TJustCommand::UndoIt(void)            // override 
  846. {
  847.     fTEView->SetJustification(fOldJust, kRedraw);
  848. }
  849.  
  850. //--------------------------------------------------------------------------------------------------
  851. #pragma segment TEDocFields
  852.  
  853. pascal void TJustCommand::Fields(TObject* obj)    // override 
  854.  
  855. {
  856.     obj->DoToField("TJustCommand", (Ptr)NULL, bClass);
  857.     obj->DoToField("fTEView", (Ptr) & fTEView, bObject);
  858.     obj->DoToField("fOldJust", (Ptr) & fOldJust, bInteger);
  859.     obj->DoToField("fNewJust", (Ptr) & fNewJust, bInteger);
  860.  
  861.     inherited::Fields(obj);
  862. }
  863.  
  864.  
  865.